//
//  MCMessageCenterModel.m
//  ZXZX
//
//  Created by MC on 2018/6/28.
//  Copyright © 2018年 TLYL01. All rights reserved.
//



#import "MCMessageCenterModel.h"
#import "NSDictionary+helper.h"
#import "NSString+Helper.h"

@interface MCMessageCenterModel ()<ApiManagerCallBackProtocol,ApiManagerProvider,ApiManagerProtocol>
{
    
    NSDictionary * _dic;
}
@end

@implementation MCMessageCenterModel
singleton_m(MCMessageCenterModel)

- (instancetype)initWithDic:(NSDictionary *)dic{
    
    if (self = [super init]) {
        _dic = dic;
    }
    return self;
}



- (void)setValue:(id)value forUndefinedKey:(NSString *)key{
    
};
-(BOOL)isShowHud{
    return YES;
}
- (BOOL)isShowError{
    return NO;
}
- (BOOL)isShowNoNet{
    return NO;
}
- (BOOL)isShowNodata{
    return NO;
}
- (enum ManagerRequestMethod)requestMethod{
    
    return ManagerRequestMethodRequestMethodRestPOST;
}

- (enum APIResponseDataType)responseDataType{
    
    return APIResponseDataTypeJson;
}
- (void)refreashDataAndShow{
    
    ApiBaseManager *baseManager = [[ApiBaseManager alloc] initWithUrlProvider:self];
    baseManager.apiCallBackDelegate = self;
    baseManager.requestCustomizeDelegate = self;
    [baseManager loadData];
    
}

- (NSDictionary<NSString *,NSString *> *)headerForManagerWithManager:(ApiBaseManager *)manager{
    
    NSString *Token=@"";
    if ([[NSUserDefaults standardUserDefaults] objectForKey:@"token"]) {
        Token=[[NSUserDefaults standardUserDefaults] objectForKey:@"token"];
    }
    
    return @{@"token":Token,@"platformCode":@"5"};
}

- (NSString *)urlPathComponentForManagerWithManager:(ApiBaseManager *)manager{
    
    return @"web-api/api/v4/message_center";
}

- (NSDictionary<NSString *,id> *)parametersForManagerWithManager:(ApiBaseManager *)manager{
    
    NSString *timeString = [NSString getCurrentTimestamp];
    
    NSDictionary *dic =_dic;
    
    NSString *jsonStr = [dic convertToJsonData];
    NSString *sign = [NSString stringWithFormat:@"%@%@%@",jsonStr,[[NSUserDefaults standardUserDefaults] objectForKey:@"token"],timeString];
    return @{@"params":jsonStr,
             @"sign":[sign MD5],
             @"timestamp":timeString
             };
}

- (void)managerCallAPIDidSuccessWithManager:(ApiBaseManager *)manager{
    
    [BKIndicationView dismiss];
    if (self.callBackSuccessBlock) {
        self.callBackSuccessBlock(manager.ResponseRawData);
    }
    
}

- (void)managerCallAPIDidFailedWithManager:(ApiBaseManager *)manager errorCode:(NSString *)errorCode{
    [BKIndicationView dismiss];
    if (self.callBackFailedBlock) {
        self.callBackFailedBlock(manager,errorCode);
    }
    NSLog(@"er=----%@",errorCode);
}
    

-(void)setMsgSiginType:(NSString *)sMsgSigin{
    
    NSInteger  MsgSigin = [sMsgSigin integerValue];
    self.isHaveInBoxList=NO;
    self.isHaveSendList=NO;
    self.isHaveSendMessage=NO;
    if ( (MsgSigin&4) == 4 ) {
        self.isHaveInBoxList=YES;
    }
    
    if ( (MsgSigin&2) == 2 ) {
        self.isHaveSendList=YES;
    }
    
    if ( (MsgSigin&1) == 1 ) {
        self.isHaveSendMessage=YES;
    }

    if (self.isHaveSendMessage||self.isHaveSendList||self.isHaveInBoxList) {
        self.isHaveNews = YES;
    }else{
        self.isHaveNews = NO;
    }

}

@end
